package com.framework.exception.controller;

import com.framework.exception.common.R;
import com.framework.exception.exception.BusinessException;
import com.framework.exception.exception.BusinessExceptionEnum;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {

    @GetMapping("info")
    public String info(){
        return "user info";
    }

    @GetMapping("list")
    public R list(){
        return R.success();
    }

    @GetMapping("div")
    public R div(@RequestParam Integer a){
        int b = 1/a;
        return R.success(b);
    }

    @GetMapping("business")
    public R business(@RequestParam("a") Integer a){
        if(a == 0){
            throw new BusinessException(BusinessExceptionEnum.User_AGE_ABNORMAL);
        }
        int b = 1/a;
        return R.success(b);
    }


}
